package com.iman.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

public abstract class SpringUtil {
    public static final List convert(SqlRowSet rowset){
        SqlRowSetMetaData metaData = rowset.getMetaData();
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        while(rowset.next()){
            Map map = getMapFromRow(rowset, metaData);
            list.add(map);
        }
        return list;
    };
    
    private static final Map getMapFromRow(SqlRowSet rs, SqlRowSetMetaData metaData){
        Map<String,Object> map = new HashMap<String, Object>();
        String[] columnNames = metaData.getColumnNames();
        for(String columnName:columnNames){
            map.put(columnName, rs.getObject(columnName));
        }
        return map;
    };
}
